package com.hmall.api.client;


import com.hmall.api.client.fallback.ItemClientFallbackFactory;
import com.hmall.api.config.DefaultFeignConfig;
import com.hmall.api.dto.ItemDTO;
import com.hmall.api.dto.OrderDetailDTO;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

@FeignClient(value = "item-service",fallbackFactory = ItemClientFallbackFactory.class)  //指定发送请求的服务名称

public interface ItemClient {

    /**
     * 使用openfeign向item-service服务发送http请求
     * @param ids
     * @return
     */
    @GetMapping("/items")
    List<ItemDTO> queryByItemIds(@RequestParam("ids") Collection<Long> ids);

    /**
     * 扣减商品库存
     * @param items
     */
    @PutMapping("/items/stock/deduct")
    void deductStock(@RequestBody List<OrderDetailDTO> items);

    /**
     * 恢复商品库存
     * @param items
     */
    @PutMapping("/items/stock/restore")
    void restoreStock(@RequestBody List<OrderDetailDTO> items);

    /**
     * 根据id查询商品
     * @param id
     * @return
     */
    @ApiOperation("根据id查询商品")
    @GetMapping("/items/{id}")
     ItemDTO queryItemById(@PathVariable("id") Long id);
}
